package br.com.guidebar.models;

import android.widget.Adapter;

import java.io.Serializable;
import java.util.NoSuchElementException;

public class Category implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;

	public Category() {
	}

	public Category(Integer id, String nome) {
		this.id = id;
		this.name = nome;
	}

	public Category(String nome) {
		this.name = nome;
	}

	public Category(int id) {
		this.id = id;
	}

	@Override
	public String toString() {
		return name;
	}

	public static Integer getPositionById(final Adapter adapter,
			final Integer id) {
		Integer posicao = 0;
		try {
			final int count = adapter.getCount();
			for (int pos = 0; pos < count; pos++) {
				Category c = (Category) adapter.getItem(pos);

				if (id == (c.getId())) {
					posicao = pos;
				}
			}
		} catch (NoSuchElementException erro) {
			erro.printStackTrace();
		}
		return posicao;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}